﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BTGISWASECO.DataLayer;
using BTGISWASECO.BusinessEntities;
using BTGISWASECO.BusinessLayer;

public partial class PresentationLayer_DefaultTab : System.Web.UI.Page
{
    HamVanBLL bll = new HamVanBLL();
    DMHuongDongChayDAL DMHuongDongChayDal = new DMHuongDongChayDAL();
    HamVanEntities HamVanEntities = new HamVanEntities();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["DataTable"] == "")
                Response.Redirect("../default.aspx");
            HamVanEntities = bll.GetHamVanEntitiesByID();
            this.txtObjectID.Value = HamVanEntities.OBJECTID.ToString();
            this.txtIDHam.Text = HamVanEntities.IDHam;
            this.txtDMA.Text = HamVanEntities.IDDMA;
            this.txtDMZ.Text = HamVanEntities.IDDMZ;
            this.txtTenHam.Text = HamVanEntities.TenHam;
            this.txtMoTaViTri.Text = HamVanEntities.MoTaViTri;
            this.txtChucNang.Text = HamVanEntities.ChucNang;
            foreach (var itemntldv in DMLoaiDonViDAL.GetList())
            {
                if (HamVanEntities.DonViQuanLyText.ToString().Trim() == itemntldv.MoTa.ToString().Trim())
                    HamVanEntities.DonViQuanLy = itemntldv.Ma;
                ListItem iteml = new ListItem(itemntldv.MoTa.ToString(), itemntldv.Ma.ToString());
                DListDonViQL.Items.Add(iteml);
            }
            DListDonViQL.SelectedValue = HamVanEntities.DonViQuanLy.ToString();

            foreach (var itemtsh in DMThuocSoHuuDAL.GetList())
            {
                if (HamVanEntities.ThuocSoHuuText.ToString().Trim() == itemtsh.MoTa.ToString().Trim())
                    HamVanEntities.ThuocSoHuu = itemtsh.Ma;
                ListItem iteml = new ListItem(itemtsh.MoTa.ToString(), itemtsh.Ma.ToString());
                DListThuocSoHuu.Items.Add(iteml);
            }
            DListThuocSoHuu.SelectedValue = HamVanEntities.ThuocSoHuu.ToString();

            this.nSLKPSuCo.Text = HamVanEntities.SoLanSuCo.ToString();
            this.txtNgayCNC.Text = HamVanEntities.NgayCNCuoi.ToString("dd/MM/yyyy");
            this.txtNguoiCNC.Text = HamVanEntities.NguoiCNCuoi.ToString();
            this.txtMaHinhAnh.Text = HamVanEntities.IDHinhAnh;
            this.txtGhiChu.Text = HamVanEntities.GhiChu;

        }//ThuocSoHuu
    }
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        HamVanEntities bk = new HamVanEntities();
        HamVanDAL HamVanDAL = new HamVanDAL();
        //HamVanEntities HamVanEntities = new HamVanEntities(Convert.ToInt32(DListDonViTC.SelectedValue = DListDonViTC.SelectedValue!=""?DListDonViTC.SelectedValue:"0"),
        //    Convert.ToInt32(DListDonViGS.SelectedValue = DListDonViGS.SelectedValue!=""?DListDonViGS.SelectedValue:"0"), this.txtNguoiCNC.Text, DateTime.Parse(this.txtNgayCNC.Text.ToString()), this.txtGhiChu.Text, this.txtMaHinhAnh.Text);
        HamVanEntities HamVanEntities = new HamVanEntities(Convert.ToInt32(txtObjectID.Value), this.txtIDHam.Text,this.txtDMZ.Text, this.txtDMA.Text,
            this.txtTenHam.Text,this.txtMoTaViTri.Text,this.txtChucNang.Text,
           Convert.ToInt32(DListDonViQL.SelectedValue = DListDonViQL.SelectedValue != "" ? DListDonViQL.SelectedValue : "0"),
           Convert.ToInt32(DListThuocSoHuu.SelectedValue = DListThuocSoHuu.SelectedValue != "" ? DListThuocSoHuu.SelectedValue : "0"),
           Convert.ToInt32(this.nSLKPSuCo.Text), this.txtNguoiCNC.Text, DateTime.Parse(Request.Form.Get("txtNgayCNC")), this.txtMaHinhAnh.Text, this.txtGhiChu.Text);
        HamVanDAL.Update1(HamVanEntities);
        //HamVanDAL.Update(Convert.ToInt32(txtObjectID.Value), txtMaDoanOng.Text, txtDMA.Text, Convert.ToInt32(DListHDChay.SelectedValue), Convert.ToDouble(this.nChieuDai.Text));
    //    Response.Redirect("../default.aspx");
        ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script language='JavaScript'>alert('Cập nhật thành công'); window.location.href ='../Default.aspx';</script>");
    }
    protected void btnHuyBo_Click(object sender, EventArgs e)
    {
        Response.Redirect("../default.aspx");
    }
}